package com.java2207.group1.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.java2207.group1.bo.IncomeBo;
import com.java2207.group1.pojo.Income;
import com.java2207.group1.service.FinancialManagementService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * @date 2022/7/21
 * @desc
 */
@Component
@Scope("prototype")     // 注意 这里要设置成多例模式
public class IncomeExcelListener extends AnalysisEventListener<IncomeBo> {

    @Autowired
    FinancialManagementService financialManagementService;

    @Override
    public void invoke(IncomeBo incomeFromExcel, AnalysisContext analysisContext) {
        Income income = new Income();
        // 属性拷贝
        BeanUtils.copyProperties(incomeFromExcel, income);

        financialManagementService.addIncome(income);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

}
